package net.ghsoft
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.describeType;
	
	import mx.collections.ArrayCollection;
	
	import net.ghsoft.AppGlobal;
	import net.ghsoft.SetupGlobal;
	
	import spark.formatters.DateTimeFormatter;
	
	public class ConvertGlobal
	{
		/**
		 * 字符串时间转时间
		 * （20140212）
		 */ 
		public static function String2Date(value:String):Date
		{
			var result:Date = new Date(int(value.substr(0, 4))
				, int(value.substr(4, 2)) - 1
				, int(value.substr(6, 2))
				, 0, 0, 0, 0);
			
			return result;
		}
		
		/**
		 * 字符串时间转时间
		 * /Date(1404545888511+0800)/
		 */ 
		public static function CString2Date(value:String):Date
		{
			var pattern:RegExp=/(\d{13}).*(\d{4})/;
			var results:Array = pattern.exec(value);
			var result:Date = new Date();
	
			if(results.length == 3)
			{
				var tt1:String = results[1];
				var tt2:String = results[2];
				result = new Date(Number(tt1));
			}
			
			return result;
		}

		public static function Date2LocalString(value:Date):String
		{
			var myformatter:DateTimeFormatter = new DateTimeFormatter();
			myformatter.dateTimePattern = "yyyy-MM-dd";//设置日期格式
			return myformatter.format(value);
		}
		
		public static function Date2SystemString(value:Date):String
		{
			var myformatter:DateTimeFormatter = new DateTimeFormatter();
			myformatter.dateTimePattern = SetupGlobal.DayLocal;//设置日期格式
			return myformatter.format(value);
		}

		public static function DateTime2LocalString(value:Date):String
		{
			var myformatter:DateTimeFormatter = new DateTimeFormatter();
			myformatter.dateTimePattern = "yyyy-MM-dd hh:mm";//设置日期格式
			return myformatter.format(value);
		}
		
		public static function DateTime2SystemString(value:Date):String
		{
			var myformatter:DateTimeFormatter = new DateTimeFormatter();
			myformatter.dateTimePattern = SetupGlobal.DayLocal + " " + SetupGlobal.TimeLocal;//设置日期格式
			return myformatter.format(value);
		}

		
		public static function Time2SystemString(value:Date):String
		{
			var myformatter:DateTimeFormatter = new DateTimeFormatter();
			myformatter.dateTimePattern = SetupGlobal.FullTimeLocal;//设置日期格式
			return myformatter.format(value);
		}

	}
}